Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isset() narrows string-key in int-keyed-array to numeric-string #3472

Merged
merged 2 commits into from
Sep 26, 2024

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Sep 23, 2024

initial steps to make isset() implementation even more similar to array_key_exists so we can in the end hopefully share the implementation

commit 1: plain 1:1 refactoring, no implementation changes
commit 2: the fix as the PR topic suggests

@staabm staabm changed the base branch from 2.0.x to 1.12.x September 23, 2024 10:37
@phpstan-bot
Copy link
Collaborator

You've opened the pull request against the latest branch 2.0.x. PHPStan 2.0 is not going to be released for months. If your code is relevant on 1.12.x and you want it to be released sooner, please rebase your pull request and change its target to 1.12.x.

);
}

$narrowedKey = AllowedArrayKeysTypes::narrowOffsetKeyType($varType, $dimType);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as a first step I think its easier to have a static method for this.

after we get more similar with the array_key_exists impl we will see whether it makes sense to move this method into the ConstantScalarType-interface, as we discussed in dresden

assertType('int', $i);
} else {
assertType('int', $i);
}
assertType('int', $i);

if (isset($arr[$s])) {
if (isset($intKeyedArr[$s])) {
assertType('numeric-string', $s);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this assertion is the interessting one, which got more precise with this PR

@staabm staabm marked this pull request as draft September 23, 2024 10:47
@staabm
Copy link
Contributor Author

staabm commented Sep 23, 2024

I am not sure whether this CI errors are related to my PR, or whether these are triggered by recent BC breaks on the 2.x branch.

-> it seems to be caused by some github infrastructure thing -> works again

@staabm staabm marked this pull request as ready for review September 23, 2024 11:56
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@staabm staabm force-pushed the isset-precise branch 4 times, most recently from 5a57c75 to fde07b5 Compare September 23, 2024 18:04
@ondrejmirtes ondrejmirtes merged commit b76fecc into phpstan:1.12.x Sep 26, 2024
482 of 499 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants